<?php

namespace App\Listeners;

use App\Events\VirtualGoods;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class HandleVirtualGoods
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  VirtualGoods  $event
     * @return void
     */
    public function handle(VirtualGoods $event)
    {
        $order = $event->order;
        $orderGoods = $order->orderGoods;
        // 只有一件商品
        if ($order->pay_status == 1 && count($orderGoods) == 1) {
            if ($orderGoods[0]->goods->is_virtual) {
                $order->order_status = 'FINISHED';
                $order->shipping_status = 1;
                $order->save();
            }
        }
    }
}
